home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / uemlsrc / keybrd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-24  |  26.6 KB  |  703 lines

  1. /* KEYBRD.C this file contain the
  2.  * keyboard processing code, for the
  3.  * MicroEMACS screen editor.
  4.  */
  5. #include        <stdio.h>
  6. #include        "ed.h"
  7.  
  8. #define FLEN    14                      /* Maximum length of function name */
  9.  
  10. typedef struct  {
  11.         short   k_code;                 /* Key code                     */
  12.         int     (*k_fp)();              /* Routine to handle it         */
  13.         char    k_mfunc[FLEN];          /* function name                */
  14. }       KEYTAB;
  15.  
  16. extern  int     clearflag();            /* Clear changed buffer flag    */
  17. extern  int     ctrlg();                /* Abort out of things          */
  18. extern  int     quit();                 /* Quit                         */
  19. extern  int     ctlxlp();               /* Begin macro                  */
  20. extern  int     ctlxrp();               /* End macro                    */
  21. extern  int     ctlxe();                /* Execute macro                */
  22. extern  int     fileinsert();           /* Insert existing file at point*/
  23. extern  int     fileread();             /* Get a file, read only        */
  24. extern  int     filevisit();            /* Get a file, read write       */
  25. extern  int     filewrite();            /* Write a file                 */
  26. extern  int     filesave();             /* Save current file            */
  27. extern  int     filename();             /* Adjust file name             */
  28. extern  int     getccol();              /* Get current column           */
  29. extern  int     gotobol();              /* Move to start of line        */
  30. extern  int     forwchar();             /* Move forward by characters   */
  31. extern  int     gotoeol();              /* Move to end of line          */
  32. extern  int     backchar();             /* Move backward by characters  */
  33. extern  int     forwline();             /* Move forward by lines        */
  34. extern  int     backline();             /* Move backward by lines       */
  35. extern  int     forwpage();             /* Move forward by pages        */
  36. extern  int     backpage();             /* Move backward by pages       */
  37. extern  int     gotobob();              /* Move to start of buffer      */
  38. extern  int     gotoeob();              /* Move to end of buffer        */
  39. extern  int     setfillcol();           /* Set fill column.             */
  40. extern  int     setindcol();            /* Set indent column            */
  41. extern  int     setmark();              /* Set mark                     */
  42. extern  int     swapmark();             /* Swap "." and mark            */
  43. extern  int     forwsearch();           /* Search forward               */
  44. extern  int     backsearch();           /* Search backward              */
  45. extern  int     forwisearch();          /* I-search forward             */
  46. extern  int     backisearch();          /* I-search backward            */
  47. extern  int     replace();              /* Search and replace           */
  48. extern  int     showcpos();             /* Show the cursor position     */
  49. extern  int     nextwind();             /* Move to the next window      */
  50. extern  int     prevwind();             /* Move to the previous window  */
  51. extern  int     onlywind();             /* Make current window only one */
  52. extern  int     splitwind();            /* Split current window         */
  53. extern  int     mvdnwind();             /* Move window down             */
  54. extern  int     mvupwind();             /* Move window up               */
  55. extern  int     enlargewind();          /* Enlarge display window.      */
  56. extern  int     shrinkwind();           /* Shrink window.               */
  57. extern  int     listbuffers();          /* Display list of buffers      */
  58. extern  int     paintbuffer();          /* Set background buffer color  */
  59. extern  int     usebuffer();            /* Switch a window to a buffer  */
  60. extern  int     killbuffer();           /* Make a buffer go away.       */
  61. extern  int     reposition();           /* Reposition window            */
  62. extern  int     refresh();              /* Refresh the screen           */
  63. extern  int     twiddle();              /* Twiddle characters           */
  64. extern  int     tab();                  /* Insert tab                   */
  65. extern  int     newline();              /* Insert CR-LF                 */
  66. extern  int     indent();               /* Insert CR-LF, then indent    */
  67. extern  int     openline();             /* Open up a blank line         */
  68. extern  int     deblank();              /* Delete blank lines           */
  69. extern  int     quote();                /* Insert literal               */
  70. extern  int     backword();             /* Backup by words              */
  71. extern  int     forwword();             /* Advance by words             */
  72. extern  int     forwdel();              /* Forward delete               */
  73. extern  int     backdel();              /* Backward delete              */
  74. extern  int     kill();                 /* Kill forward                 */
  75. extern  int     yank();                 /* Yank back from killbuffer.   */
  76. extern  int     upperword();            /* Upper case word.             */
  77. extern  int     lowerword();            /* Lower case word.             */
  78. extern  int     upperregion();          /* Upper case region.           */
  79. extern  int     lowerregion();          /* Lower case region.           */
  80. extern  int     capword();              /* Initial capitalize word.     */
  81. extern  int     delfword();             /* Delete forward word.         */
  82. extern  int     delbword();             /* Delete backward word.        */
  83. extern  int     killregion();           /* Kill region.                 */
  84. extern  int     copyregion();           /* Copy region to kill buffer.  */
  85. extern  int     writereg();             /* write defined region to file */
  86. extern  int     quickexit();            /* low keystroke style exit.    */
  87. extern  int     goteop();               /* goto end of paragraph */
  88. extern  int     gotbop();               /* goto beginning of paragraph */
  89. extern  int     unkncom();              /* unknown command BEEP */
  90. extern  int     ftopunct();             /* move forward to next punctuation */
  91. extern  int     btopunct();             /* move backward to last punctuation */
  92. extern  int     forwsent();             /* forward to end of sentence */
  93. extern  int     backsent();             /* backward to beginning of sentence */
  94. extern  int     fillpar();              /* fill paragraph to fill column */
  95. extern  int     setpage();              /* set page size from arg */
  96. extern  int     paginate();             /* insert '\f' every page */
  97. extern  int     pageforw();             /* move forward set page length */
  98. extern  int     pageback();             /* move back set page length */
  99. extern  int     print();                /* print buffer with heading */
  100. extern  int     wc();                   /* word and line count of buffer */
  101. extern  int     retversion();           /* version date */
  102. extern  int     kermit();               /* file transfer */
  103.  
  104. /* From here on the commands are from misc.c */
  105. extern  int     mdropln();              /* drop current line and move up*/
  106. extern  int     mindnl();               /* indent subsequent NL same as this */
  107. extern  int     mdeleln();              /* delete entire line from beginning */
  108. extern  int     mdelwln();              /* delete entire line including NL   */
  109. extern  int     mdelind();              /* delete beginning line indentation */
  110. extern  int     markpar();              /* mark paragraph sets mark */
  111. extern  int     tglcase();              /* toggle case of letter at point */
  112. extern  int     killsent();             /* kill sentence forward sets mark */
  113. extern  int     grtw();                 /* remove trailing white space */
  114. extern  int     twaddle();              /* transpaose two words in place */
  115. extern  int     clowsp();               /* close up intervening white space */
  116. extern  int     mrflush();              /* flush right current line */
  117. extern  int     mcenter();              /* center current line */
  118. extern  int     setmode();              /* set a mode for a buffer */
  119. extern  int     sglmode();              /* set global mode      */
  120. extern  int     rettpa();               /* show available memory and usage */
  121. extern  int     showtime();             /* return current time  */
  122. extern  int     goline();               /* goto line in text */
  123. extern  int     enumerate();            /* start or incr. counter variable */
  124. extern  int     gospell();              /* search forward for spell mark */
  125. extern  int     mdoncom();              /* execute a named command */
  126.  
  127. /* functions in macros.c to allow 26 keyboard macros */
  128. extern  int     putmacro();             /* print line macros in text    */
  129. extern  int     getmacro();             /* copy cureent key-mac to key  */
  130.  
  131. /* shell commands */
  132. extern  int     shell();                /* run one command or run cc    */
  133. extern  int     commfil();              /* read alias file              */
  134. extern  int     setpath();              /* get/set path and drive       */
  135.  
  136. /*
  137.  * Command table.
  138.  * This table  is *roughly* in ASCII
  139.  * order, left to right across the characters
  140.  * of the command. This expains the funny
  141.  * location of the control-X commands.
  142.  */
  143. KEYTAB  keytab[] = {
  144.         CTRL|'@',               &setmark,
  145.         "setmark",
  146.         CTRL|'A',               &gotobol,
  147.         "gotobol",
  148.         CTRL|'B',               &backchar,
  149.         "backchar",
  150.         CTRL|'C',               &shell,
  151.         "shell",
  152.         CTRL|'D',               &forwdel,
  153.         "forwdel",
  154.         CTRL|'E',               &gotoeol,
  155.         "gotoeol",
  156.         CTRL|'F',               &forwchar,
  157.         "forwchar",
  158.         CTRL|'G',               &ctrlg,
  159.         "ctrlg",
  160.         CTRL|'H',               &backchar,
  161.         "backchar",
  162.         CTRL|'I',               &tab,
  163.         "tab",
  164.         CTRL|'J',               &indent,
  165.         "indent",
  166.         CTRL|'K',               &mdeleln,
  167.         "mdeleln",
  168.         CTRL|'L',               &refresh,
  169.         "refresh",
  170.         CTRL|'M',               &newline,
  171.         "newline",
  172.         CTRL|'N',               &forwline,
  173.         "forwline",
  174.         CTRL|'O',               &openline,
  175.         "openline",
  176.         CTRL|'P',               &backline,
  177.         "backline",
  178.         CTRL|'Q',               "e,
  179.         "quote",
  180.         CTRL|'R',               &backsearch,
  181.         "backsearch",
  182.         CTRL|'S',               &forwsearch,
  183.         "forwsearch",
  184.         CTRL|'T',               &twiddle,
  185.         "twiddle",
  186.         CTRL|'V',               &forwpage,
  187.         "forwpage",
  188.         CTRL|'W',               &killregion,
  189.         "killregion",
  190.         CTRL|'Y',               &yank,
  191.         "yank",
  192.         CTRL|'Z',               &quickexit,
  193.         "quickexit",
  194.         CTRL|'\\',              &unkncom,
  195.         "unkncom",
  196.         CTRL|'_',               &kermit,
  197.         "kermit",
  198.         CTRL|'^',               &unkncom,
  199.         "unkncom",
  200.         CTLX|CTRL|'A',          &unkncom,
  201.         "unkncom",
  202.         CTLX|CTRL|'B',          &listbuffers,
  203.         "listbuffers",
  204.         CTLX|CTRL|'C',          &quit,
  205.         "quit",
  206.         CTLX|CTRL|'D',          &unkncom,
  207.         "unkncom",
  208.         CTLX|CTRL|'E',          &commfil,
  209.         "commfil",
  210.         CTLX|CTRL|'F',          &filename,
  211.         "filename",
  212.         CTLX|CTRL|'G',          &ctrlg,
  213.         "ctrlg",
  214.         CTLX|CTRL|'H',          &unkncom,
  215.         "unkncom",
  216.         CTLX|CTRL|'I',          &print,
  217.         "print",
  218.         CTLX|CTRL|'J',          &unkncom,
  219.         "unkncom",
  220.         CTLX|CTRL|'K',          &unkncom,
  221.         "unkncom",
  222.         CTLX|CTRL|'L',          &lowerregion,
  223.         "lowerregion",
  224.         CTLX|CTRL|'M',          &unkncom,
  225.         "unkncom",
  226.         CTLX|CTRL|'N',          &mvdnwind,
  227.         "mvdnwind",
  228.         CTLX|CTRL|'O',          &deblank,
  229.         "deblank",
  230.         CTLX|CTRL|'P',          &mvupwind,
  231.         "mvupwind",
  232.         CTLX|CTRL|'Q',          &unkncom,
  233.         "unkncom",
  234.         CTLX|CTRL|'R',          &fileread,
  235.         "fileread",
  236.         CTLX|CTRL|'S',          &filesave,
  237.         "filesave",
  238.         CTLX|CTRL|'T',          &showtime,
  239.         "showtime",
  240.         CTLX|CTRL|'U',          &upperregion,
  241.         "upperregion",
  242.         CTLX|CTRL|'V',          &filevisit,
  243.         "filevisit",
  244.         CTLX|CTRL|'W',          &filewrite,
  245.         "filewrite",
  246.         CTLX|CTRL|'X',          &swapmark,
  247.         "swapmark",
  248.         CTLX|CTRL|'Y',          &unkncom,
  249.         "unkncom",
  250.         CTLX|CTRL|'Z',          &shrinkwind,
  251.         "shrinkwind",
  252.         CTLX|'!',               &paginate,
  253.         "paginate",
  254.         CTLX|'#',               &setpage,
  255.         "setpage",
  256.         CTLX|'+',               &pageforw,
  257.         "pageforw",
  258.         CTLX|'-',               &pageback,
  259.         "pageback",
  260.         CTLX|'.',               &setindcol,
  261.         "setindcol",
  262.         CTLX|'(',               &ctlxlp,
  263.         "ctlxlp",
  264.         CTLX|')',               &ctlxrp,
  265.         "ctlxrp",
  266.         CTLX|'*',               &retversion,
  267.         "retversion",
  268.         CTLX|'<',               &btopunct,
  269.         "btopunct",
  270.         CTLX|'=',               &showcpos,
  271.         "showcpos",
  272.         CTLX|'>',               &ftopunct,
  273.         "ftopunct",
  274.         CTLX|'0',               &unkncom,
  275.         "unkncom",
  276.         CTLX|'1',               &onlywind,
  277.         "onlywind",
  278.         CTLX|'2',               &splitwind,
  279.         "splitwind",
  280.         CTLX|'3',               &unkncom,
  281.         "unkncom",
  282.         CTLX|'4',               &unkncom,
  283.         "unkncom",
  284.         CTLX|'5',               &unkncom,
  285.         "unkncom",
  286.         CTLX|'6',               &unkncom,
  287.         "unkncom",
  288.         CTLX|'7',               &unkncom,
  289.         "unkncom",
  290.         CTLX|'8',               &unkncom,
  291.         "unkncom",
  292.         CTLX|'9',               &unkncom,
  293.         "unkncom",
  294.         CTLX|'A',               &unkncom,
  295.         "unkncom",
  296.         CTLX|'B',               &usebuffer,
  297.         "usebuffer",
  298.         CTLX|'C',               &paintbuffer,
  299.         "paintbuffer",
  300.         CTLX|'D',               &setpath,
  301.         "setpath",
  302.         CTLX|'E',               &ctlxe,
  303.         "ctlxe",
  304.         CTLX|'F',               &setfillcol,
  305.         "setfillcol",
  306.         CTLX|'H',               &unkncom,
  307.         "unkncom",
  308.         CTLX|'I',               &fileinsert,
  309.         "fileinsert",
  310.         CTLX|'J',               &unkncom,
  311.         "unkncom",
  312.         CTLX|'K',               &killbuffer,
  313.         "killbuffer",
  314.         CTLX|'L',               &unkncom,
  315.         "unkncom",
  316.         CTLX|'M',               &setmode,
  317.         "setmode",
  318.         CTLX|'N',               &nextwind,
  319.         "nextwind",
  320.         CTLX|'O',               &prevwind,
  321.         "prevwind",
  322.         CTLX|'P',               &prevwind,
  323.         "prevwind",
  324.         CTLX|'Q',               &unkncom,
  325.         "unkncom",
  326.         CTLX|'R',               &writereg,
  327.         "writereg",
  328.         CTLX|'S',               &gospell,
  329.         "gospell",
  330.         CTLX|'T',               &unkncom,
  331.         "unkncom",
  332.         CTLX|'U',               &unkncom,
  333.         "unkncom",
  334.         CTLX|'V',               &unkncom,
  335.         "unkncom",
  336.         CTLX|'W',               &wc,
  337.         "wc",
  338.         CTLX|'Y',               &unkncom,
  339.         "unkncom",
  340.         CTLX|'Z',               &enlargewind,
  341.         "enlargewind",
  342.         CTLX|'\\',              &grtw,
  343.         "grtw",
  344.         CTLX|'`',               &getmacro,
  345.         "getmacro",
  346.         CTLX|'~',               &shell,
  347.         "shell",
  348.         CTLX|SPEC|'p',          &swapmark,
  349.         "swapmark",
  350.         META|CTRL|'B',          &backword,
  351.         "backword",
  352.         META|CTRL|'C',          &mcenter,
  353.         "mcenter",
  354.         META|CTRL|'F',          &forwword,
  355.         "forwword",
  356.         META|CTRL|'G',          &ctrlg,
  357.         "ctrlg",
  358.         META|CTRL|'H',          &backword,
  359.         "backword",
  360.         META|CTRL|'I',          &kill,
  361.         "kill",
  362.         META|CTRL|'K',          &mdelwln,
  363.         "mdelwln",
  364.         META|CTRL|'M',          &unkncom,
  365.         "unkncom",
  366.         META|CTRL|'N',          &enumerate,
  367.         "enumerate",
  368.         META|CTRL|'O',          &clowsp,
  369.         "clowsp",
  370.         META|CTRL|'P',          &tglcase,
  371.         "tglcase",
  372.         META|CTRL|'R',          &mrflush,
  373.         "mrflush",
  374.         META|CTRL|'S',          &forwisearch,
  375.         "forwisearch",
  376.         META|CTRL|'T',          &backisearch,
  377.         "backisearch",
  378.         META|'!',               &reposition,
  379.         "reposition",
  380.         META|'.',               &gotoeob,
  381.         "gotoeob",
  382.         META|',',               &gotobob,
  383.         "gotobob",
  384.         META|'>',               &gotoeob,
  385.         "gotoeob",
  386.         META|'<',               &gotobob,
  387.         "gotobob",
  388.         META|' ',               &setmark,
  389.         "setmark",
  390.         META|'@',               &rettpa,
  391.         "rettpa",
  392.         META|'A',               &backsent,
  393.         "backsent",
  394.         META|'B',               &backword,
  395.         "backword",
  396.         META|'C',               &capword,
  397.         "capword",
  398.         META|'D',               &delfword,
  399.         "delfword",
  400.         META|'E',               &forwsent,
  401.         "forwsent",
  402.         META|'F',               &forwword,
  403.         "forwword",
  404.         META|'G',               &goline,
  405.         "goline",
  406.         META|'H',               &markpar,
  407.         "markpar",
  408.         META|'I',               &unkncom,
  409.         "unkncom",
  410.         META|'J',               &mindnl,
  411.         "mindnl",
  412.         META|'K',               &killsent,
  413.         "killsent",
  414.         META|'L',               &lowerword,
  415.         "lowerword",
  416.         META|'M',               &sglmode,
  417.         "sglmode",
  418.         META|'N',               &goteop,
  419.         "goteop",
  420.         META|'O',               &mdropln,
  421.         "mdropln",
  422.         META|'P',               &gotbop,
  423.         "gotbop",
  424.         META|'Q',               &fillpar,
  425.         "fillpar",
  426.         META|'R',               &replace,
  427.         "replace",
  428.         META|'S',               &unkncom,
  429.         "unkncom",
  430.         META|'T',               &twaddle,
  431.         "twaddle",
  432.         META|'U',               &upperword,
  433.         "upperword",
  434.         META|'V',               &backpage,
  435.         "backpage",
  436.         META|'W',               ©region,
  437.         "copyregion",
  438.         META|'X',               &mdoncom,
  439.         "mdoncom",
  440.         META|'Y',               &unkncom,
  441.         "unkncom",
  442.         META|'Z',               &unkncom,
  443.         "unkncom",
  444.         META|'\\',              &mdelind,
  445.         "mdelind",
  446.         META|'~',               &clearflag,
  447.         "clearflag",
  448.         META|0x7F,              &delbword,
  449.         "delbword",
  450. #if     ST
  451.         SPEC|'H',               &backline,
  452.         "backline",
  453.         SPEC|'P',               &forwline,
  454.         "forwline",
  455.         SPEC|'K',               &backchar,
  456.         "backchar",
  457.         SPEC|'M',               &forwchar,
  458.         "forwchar",
  459.         SPEC|'b',               &kermit,
  460.         "kermit",
  461.         SPEC|'a',               &yank,
  462.         "yank",
  463.         SPEC|'R',               &openline,
  464.         "openline",
  465.         SPEC|'S',               &backdel,
  466.         "backdel",
  467.         SPEC|'G',               &refresh,
  468.         "refresh",
  469.         SPEC|'q',               &forwdel,
  470.         "forwdel",
  471.         SPEC|'r',               &indent,
  472.         "indent",
  473.         SPEC|'c',               &backword,
  474.         "backword",
  475.         SPEC|'d',               &forwword,
  476.         "forwword",
  477.         SPEC|'e',               &grtw,
  478.         "grtw",
  479.         SPEC|'f',               &retversion,
  480.         "retversion",
  481.         SPEC|'g',               &gotobol,
  482.         "gotobol",
  483.         SPEC|'h',               &gotoeol,
  484.         "gotoeol",
  485.         SPEC|'i',               &unkncom,
  486.         "unkncom",
  487.         SPEC|'J',               &pageback,
  488.         "pageback",
  489.         SPEC|'N',               &pageforw,
  490.         "pageforw",
  491.         SPEC|'j',               &backsent,
  492.         "backsent",
  493.         SPEC|'k',               &forwsent,
  494.         "forwsent",
  495.         SPEC|'l',               &unkncom,
  496.         "unkncom",
  497.         SPEC|'m',               &gotbop,
  498.         "gotbop",
  499.         SPEC|'n',               &goteop,
  500.         "goteop",
  501.         SPEC|'o',               &unkncom,
  502.         "unkncom",
  503.         SPEC|'D',               &quickexit,
  504.         "quickexit",
  505.         SPEC|'C',               &filesave,
  506.         "filesave",
  507.         SPEC|'B',               &filewrite,
  508.         "filewrite",
  509.         SPEC|'A',               &filevisit,
  510.         "filevisit",
  511.         SPEC|'@',               &fileread,
  512.         "fileread",
  513.         SPEC|'?',               &fileinsert,
  514.         "fileinsert",
  515.         SPEC|'>',               &writereg,
  516.         "writereg",
  517.         SPEC|'=',               &filename,
  518.         "filename",
  519.         SPEC|'<',               &listbuffers,
  520.         "listbuffers",
  521.         SPEC|';',               &setmark,
  522.         "setmark",
  523. #endif
  524.         AGRAVE,                 &putmacro,
  525.         "putmacro",
  526.         0x7F,                   &backdel,
  527.         "backdel"
  528. };
  529.  
  530. #define NKEYTAB (sizeof(keytab)/sizeof(keytab[0]))
  531.  
  532. #if     LK201
  533. /*
  534.  * Mapping table for all of the funny
  535.  * keys with the numeric parameters on the LK201.
  536.  * Indexed by the code, which is between 0 (unused) and
  537.  * 34 (F20). An entry of 0 means no mapping. The map
  538.  * goes to command keys. If I had a "special" bit,
  539.  * I could use the code in the escape sequence as a
  540.  * key code, and return (for example) "do" as
  541.  * SPECIAL + 29. Then the dispatch would be
  542.  * done by the default keymap. This is probably a
  543.  * better way to go.
  544.  */
  545. short   lkmap[] = {
  546.         0,
  547.         CTRL|'S',                       /* 1    Find                    */
  548.         CTRL|'Y',                       /* 2    Insert here             */
  549.         CTRL|'W',                       /* 3    Remove                  */
  550.         CTRL|'@',                       /* 4    Select                  */
  551.         META|'V',                       /* 5    Previous screen         */
  552.         CTRL|'V',                       /* 6    Next screen             */
  553.         0,
  554.         0,
  555.         0,
  556.         0,                              /* 10   Compose                 */
  557.         0,
  558.         0,                              /* 12   Print screen            */
  559.         0,
  560.         0,                              /* 14   F4                      */
  561.         0,
  562.         0,
  563.         0,                              /* 17   F6                      */
  564.         0,                              /* 18   F7                      */
  565.         0,                              /* 19   F8                      */
  566.         0,                              /* 20   F9                      */
  567.         0,                              /* 21   F10                     */
  568.         0,
  569.         0,
  570.         0,
  571.         0,
  572.         0,                              /* 26   F14                     */
  573.         0,
  574.         0,                              /* 28   Help                    */
  575.         CTLX|'E',                       /* 29   Do      C-X E           */
  576.         0,
  577.         CTLX|'P',                       /* 31   F17     C-X P           */
  578.         CTLX|'N',                       /* 32   F18     C-X N           */
  579.         CTLX|'Z',                       /* 33   F19     C-X Z           */
  580.         CTLX|CTRL|'Z'                   /* 34   F20     C-X C-Z         */
  581. };
  582. #endif
  583.  
  584. /*
  585.  * This is the general command execution
  586.  * routine. It handles the fake binding of all the
  587.  * keys to "self-insert". It also clears out the "thisflag"
  588.  * word, and arranges to move it to the "lastflag", so that
  589.  * the next command can look at it. Return the status of
  590.  * command.
  591.  */
  592. execute(c, f, n)
  593. register int c, f, n;
  594. {
  595.         register KEYTAB *ktp;
  596.         register int    status;
  597.  
  598.         ktp = &keytab[0];                       /* Look in key table.   */
  599.         while (ktp < &keytab[NKEYTAB]) {
  600.                 if (ktp->k_code == c) {
  601.                         thisflag = 0;
  602.                         status   = (*ktp->k_fp)(f, n);
  603.                         lastflag = thisflag;
  604.                         return (status);
  605.                 }
  606.                 ++ktp;
  607.         }
  608.  
  609.         /*
  610.          * If inwrap a space was typed, fill column is defined, the argument
  611.          * is non-negative, and we are now past fill column, perform word wrap.
  612.          */
  613.         if ((curbp->b_bmode&BMWRAP) != 0 && c == ' ' && fillcol > 0
  614.                 && n>=0 && getccol(FALSE) > fillcol)
  615.                 {
  616.                 linsert(1, c);  /* we want the space */
  617.                 wrapword(FALSE, NULL);
  618.                 }
  619.         if ((c>=0x20 && c<=0x7E)                /* Self inserting.      */
  620.         ||  (c>=0xA0 && c<=0xFE)) {
  621.                 if (n <= 0) {                   /* Fenceposts.          */
  622.                         lastflag = 0;
  623.                         return (n<0 ? FALSE : TRUE);
  624.                 }
  625.                 thisflag = 0;                   /* For the future.      */
  626.                 status   = linsert(n, c);
  627.                 lastflag = thisflag;
  628.                 return (status);
  629.         }
  630.         lastflag = 0;                           /* Fake last flags.     */
  631.         return (FALSE);
  632. }
  633.  
  634. bindkey(code,name)
  635. register short code;
  636. register char *name;
  637. {
  638.         register KEYTAB *oktp,*nktp;
  639.         int found = FALSE;
  640.  
  641.         nktp = &keytab[0];      /* bind to this key */
  642.         oktp = &keytab[0];      /* the function to bind */
  643.         /* look through to find keytab assoc with "name" */
  644.         while (oktp < &keytab[NKEYTAB]) {
  645.                 if (strcmp(oktp->k_mfunc,name)==NULL) {
  646.                         found = TRUE;
  647.                         break;
  648.                 }
  649.                 ++oktp;
  650.         }
  651.         if (found)
  652.                 /* search for key */
  653.                 while (nktp < &keytab[NKEYTAB]) {
  654.                         if (nktp->k_code == code) {
  655.                                 strcpy(nktp->k_mfunc,oktp->k_mfunc);
  656.                                 nktp->k_fp=oktp->k_fp;
  657.                                 return(TRUE);
  658.                         }
  659.                         ++nktp;
  660.                 }
  661.         return(FALSE);
  662. }
  663.  
  664. /* given a keycode value, return a pointer to the name of that function
  665.  * and get the function's name into `name'.
  666.  */
  667. char *
  668. getfname(kcode,name)
  669. register short kcode;
  670. char name[];
  671. {
  672.         register KEYTAB *ktp;
  673.  
  674.         ktp = &keytab[0];       /* the function to find */
  675.         /* look through to find keytab assoc with "code" */
  676.         while (ktp < &keytab[NKEYTAB]) {
  677.                 if (ktp->k_code == kcode)
  678.                         {
  679.                         strcpy(name,ktp->k_mfunc);
  680.                         return(ktp->k_mfunc);
  681.                         }
  682.                 ++ktp;
  683.         }
  684.         return((char *)NULL);   /* not found */
  685. }
  686.  
  687. /* return the code associated with `name' */
  688. short
  689. getktpcode(name)
  690. char name[];
  691. {
  692.         register KEYTAB *ktp;
  693.  
  694.         ktp = &keytab[0];       /* the function to find */
  695.         /* look through to find keytab assoc with "name" */
  696.         while (ktp < &keytab[NKEYTAB]) {
  697.                 if (strcmp(ktp->k_mfunc,name) == NULL)
  698.                         return(ktp->k_code);
  699.                 ++ktp;
  700.         }
  701.         return(NULL);
  702. }
  703.